/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.support.notice;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import com.qihoo.gamecenter.sdk.common.h.b;
import com.qihoo.gamecenter.sdk.common.i.s;
import com.qihoo.gamecenter.sdk.support.notice.view.NoticeView;
import com.qihoo.gamecenter.sdk.support.notice.view.NoticeView.a;
import java.lang.ref.WeakReference;
import org.json.JSONObject;

public class a {
    private Context a;
    private NoticeView b;
    private WindowManager c;
    private WindowManager.LayoutParams d;
    private Handler e;
    private static a f = null;

    private void a() {
        if (s.n(this.a))
            this.e.sendEmptyMessageDelayed(100, 1000L);
        else
            c();
    }

    private a(Context paramContext) {
        this.a = paramContext;
        this.e = new a(this);
        b();
    }

    private void b() {
        this.c = ((WindowManager) this.a.getSystemService("window"));
        this.d = new WindowManager.LayoutParams();
        this.d.type = 2003;
        this.d.gravity = 17;
        this.d.format = -2;
        this.b = new NoticeView(this.a);
        this.b.setNoticeGravity(51);
        this.b.setNoticeClosedListener(new NoticeView.a() {
            public void a() {
                a.b(a.this);
            }
        });
    }

    private void c() {
        if ((this.b != null) && (this.b.getParent() != null))
            this.c.removeView(this.b);
        if (!(this.e.hasMessages(100)))
            return;
        this.e.removeMessages(100);
    }

    private void a(String paramString1, String paramString2) {
        if ((TextUtils.isEmpty(paramString1)) || (TextUtils.isEmpty(paramString2)) || (!(s.n(this.a))))
            return;
        this.b.a(paramString1, paramString2);
        this.c.addView(this.b, this.d);
        this.e.sendEmptyMessageDelayed(100, 1000L);
    }

    public static a a(Context paramContext) {
        if (f == null)
            f = new a(paramContext);
        return f;
    }

    public void a(String paramString) {
        Intent localIntent = new Intent();
        localIntent.putExtra("type_id", "1");
        if (!(TextUtils.isEmpty(paramString)))
            localIntent.putExtra("user_id", paramString);
        new com.qihoo.gamecenter.sdk.support.notice.a.a(this.a, localIntent).a(new b() {
            public void a(String paramString, Context paramContext) {
                super.a(paramString, paramContext);
                com.qihoo.gamecenter.sdk.support.g.a.a("NoticeManager", new Object[] {
                        " --> NoticeTask.callBack(Context ctx) -- > result = ", paramString });
                JSONObject localJSONObject = b();
                if (localJSONObject == null)
                    return;
                int i = localJSONObject.optInt("error_code");
                if (i != 0)
                    return;
                localJSONObject = localJSONObject.optJSONObject("notice");
                if (localJSONObject == null)
                    return;
                String str1 = localJSONObject.optString("title");
                String str2 = localJSONObject.optString("content");
                a.a(a.this, str1, str2);
            }
        }, new String[0]);
    }

    private static class a extends Handler {
        private WeakReference a;

        public a(a parama) {
            this.a = new WeakReference(parama);
        }

        public void handleMessage(Message paramMessage) {
            a locala = (a) this.a.get();
            if (locala == null)
                return;
            switch (paramMessage.what) {
            case 100:
                a.a(locala);
            }
        }
    }
}